import QtQuick 1.0

Rectangle {
    id: button

    property string backgroundColor: buttonMouseArea.pressed ?
            root.constants.activeColor :
            root.constants.highlightColor;
    property string iconFilename
    property real iconOpacity: 1.0
    property alias pressed: buttonMouseArea.pressed

    signal tapped

    radius: width * root.constants.defaultRelativeRadius
    border.width: root.constants.defaultBorderWidth
    border.color: buttonMouseArea.pressed ?
            root.constants.activeColor :
            root.constants.highlightColor;
    smooth: true

    gradient: Gradient {
        GradientStop { position: 0.0; color: root.constants.defaultBackgroundColor }
        GradientStop { position: 0.2; color: root.constants.defaultBackgroundColor }
        GradientStop { position: 1.0; color: backgroundColor }
    }

    Image {
        id: buttonIcon
        anchors.fill: parent
        anchors.centerIn: parent.Center
        z: 1
        opacity: buttonMouseArea.pressed ? iconOpacity : 0.8
        fillMode: Image.PreserveAspectFit
        smooth: true
        source: button.iconFilename

        Behavior on opacity {
            NumberAnimation { duration: root.constants.shortAnimationDuration }
        }
    }

    MouseArea {
        id: buttonMouseArea
        anchors.fill: parent

        onClicked: {
            parent.tapped();
            haptics.buttonTapFeedback();
        }
    }
}

// End of file.
